package com.mt.roll.wms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.EnabledParam;
import com.mt.roll.core.params.IdListParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdListVo;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.MaterialAttrParam;
import com.mt.roll.wms.params.MaterialAttrQueryParam;
import com.mt.roll.wms.service.MaterialAttrService;
import com.mt.roll.wms.vo.MaterialAttrVo;
import feign.Contract;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @Author weihongyang
 * @Date 2020/12/30 15:59
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "material-attr")
@Slf4j
@Api(value = "平台物料属性管理", tags = "平台物料属性管理接口", hidden = false)
public class MaterialAttrController {
    @Autowired
    private MaterialAttrService materialAttrService;

    @PostMapping(value = "get")
    @ApiOperation(value = "获取物料属性")
    private R<MaterialAttrVo> get(@Validated @RequestBody IdParam idParam) {
        return materialAttrService.get(idParam);
    }

    @PostMapping(value = "list")
    @ApiOperation(value = "获取xx列表")
    private R<List<MaterialAttrVo>> list(@Validated({Contract.Default.class}) @RequestBody MaterialAttrQueryParam materialAttrQueryParam) {
        return materialAttrService.list(materialAttrQueryParam);
    }

    @PostMapping(value = "page")
    @ApiOperation(value = "获取分页物料属性")
    private R<PageVo<MaterialAttrVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody MaterialAttrQueryParam materialAttrQueryParam) {

        return materialAttrService.page(materialAttrQueryParam);
    }

    @PostMapping(value = "tree")
    @ApiOperation(value = "获取xx树列表")
    private R<List<MaterialAttrVo>> tree(@Validated({Default.class}) @RequestBody MaterialAttrQueryParam materialAttrQueryParam) {
        return materialAttrService.tree(materialAttrQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody MaterialAttrParam materialAttrParam) {
        return materialAttrService.add(materialAttrParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody MaterialAttrParam materialAttrParam) {
        return materialAttrService.update(materialAttrParam);
    }

    @PostMapping(value = "enabled")
    @ApiOperation(value = "启停xx")
    private R<IdVo> enabled(@Validated @RequestBody EnabledParam enabledParam) {
        return materialAttrService.enabled(enabledParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除物料信息")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return materialAttrService.delete(idParam);
    }

    @PostMapping(value = "batchDelete")
    @ApiOperation(value = "批量删除xx")
    private R<IdListVo> delete(@Validated @RequestBody IdListParam idListParam) {
        return materialAttrService.delete(idListParam);
    }

    @PostMapping(value = "get-code")
    @ApiOperation(value = "获取xx code")
    private R<String> getCode() {
        return materialAttrService.getCode();
    }

}
